//---------------------------------------------------------------------------------
// Copyright (c) 2008 VoiceLynx Project
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
//     1. The origin of this software must not be misrepresented; you must not
//        claim that you wrote the original software. If you use this software
//        in a product, an acknowledgment in the product documentation would be
//        appreciated but is not required.
//
//     2. Altered source versions must be plainly marked as such, and must not be
//        misrepresented as being the original software.
//
//     3. This notice may not be removed or altered from any source
//        distribution.
//---------------------------------------------------------------------------------

#ifndef __VLCore_h__
#define __VLCore_h__

#include "VLPrerequisites.h"

#include "VLPackets.h"
#include "VLPacketLogic.h"

#include "VLSoundManager.h"
#include "VLControl.h"

#include "VLUser.h"

class VLBaseCore
{
public:
  VLBaseCore(VLPacketLogicPtr packetLogic);
  virtual ~VLBaseCore();

  VLRawOutgoingPacketPtr takeOutgoingData();
  void giveIncomingData(VLRawIncomingPacketPtr data);
  VLDisconnectRequestPtr takeDisconnectRequest();

  void onConnect(VLHostId hostId);
  void onDisconnect(VLHostId hostId);

  VLPacketLogic &getPacketLogic();

  virtual void think() = 0;

protected:
  VLPacketLogicPtr   mPacketLogic;
  VLPacketTranslator mPacketTranslator;

  VLPeerList         mUsers;
};


//! The "core" object that unites the seperate pieces (networking, sound, etc)

/// Note that the UI or server main() creates and uses this class
///
class VLClientCore : public VLBaseCore
{
public:
  //! Create the core
  VLClientCore(VLPacketLogicPtr packetLogic);

  VLIController *getController();
  void setController(VLIController *controller);

  float getTxVolume();

  void think();

private:
  VLSoundManagerPtr mSoundManager;

  VLCodecPtr       mCodec;
  VLEncoderPtr     mEncoder;
  VLDecoderPtr     mDecoder;

  VLStaticSoundPtr mStartTalkingSound;
  VLStaticSoundPtr mStopTalkingSound;

  VLIController   *mController;
  bool             mIsTransmitting;
};

class VLServerCore : public VLBaseCore
{
public:

  //! Create the core
  VLServerCore(VLPacketLogicPtr packetLogic);

  //void createChannel(const VLString &name, const VLString &description);
  //void deleteChannel(VLChannel *channel);
  //void switchToChannel(VLChannel *channel);
  //void getChannels(VLChannelList &channelList);

  //void addUser(VLUser *user);
  //void kickUser(VLUser *user);
  //void setUserGain(VLUser *user);
  //void getUsers(VLUserList &userList);

  //void getServerSettings();
  //void setServerSettings();
  //void canSetServerSettings();

  //void getChannels();
  //void switchToChannel();
  //void addChannel();
  //void canAddChannel();

  //void getUserSettings();
  //void setUserSettings();

  void think();

private:

  //VLChannelList mChannels;
};


#endif